﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COFE.Core.Actions
{
    public interface IWork
    {
        #region Public Properties

        /// <summary>
        /// _id of the current SimpleWork.
        /// </summary>        
        Guid ID { get; }

        /// <summary>
        /// Identifiable name for the current work, 
        /// work scheduler ignore duplicated (same name) work, unless Name is not set (e.g. null).
        /// </summary>
        string Name { get; }

        /// <summary>
        /// Description of the current SimpleWork.
        /// </summary>
        string Description { get; }

        /// <summary>
        /// Returns the time the SimpleWork constructed.
        /// </summary>
        DateTime ConstructTimeUtc { get; }

        /// <summary>
        /// Return the time DoWork() called.
        /// </summary>
        DateTime StartTimeUtc { get; }

        ///// <summary>
        ///// If serializable (WorkAttribute.IsSerializable.
        ///// This work can be recreated using FactoryRegister
        ///// .FinidFactory(WorkAttrbuite.WorkTypeName).Construct() method, 
        ///// </summary>
        //string ConstructParameters { get; }

        /// <summary>
        /// Return the time DoWork() is ended.
        /// </summary>
        DateTime EndTimeUtc { get; }

        /// <summary>
        /// All message received from WorkMessageEvent.
        /// </summary>
        string[] MessageLog { get; }

        /// <summary>
        /// Last WorkMessageEvent event raised.
        /// </summary>
        WorkMessageEventArgs LastMessage { get; }

        /// <summary>
        /// Last WorkProgress event raised.
        /// </summary>
        WorkProgressEventArgs LastProgress { get; }

        /// <summary>
        /// Last WorkFinished event raised.
        /// </summary>
        WorkFinishedEventArgs Result { get; }

        /// <summary>
        /// Return the PercentageCompleted, or -1 if not applied.
        /// </summary>
        int PercentageCompleted { get; }

        /// <summary>
        /// Return the current work status.
        /// </summary>
        StatusType WorkStatus { get; }

        /// <summary>
        /// Return whether the SimpleWork is paused.
        /// </summary>
        bool Paused { get; set; }

        /// <summary>
        /// Return whether the SimpleWork is cancelled.
        /// </summary>
        bool Aborted { get; }

        #endregion

        #region Events

        event EventHandler<WorkProgressEventArgs> WorkProgress;
        event EventHandler<WorkMessageEventArgs> WorkMessage;
        event EventHandler<WorkEventArgs> WorkStart;
        event EventHandler<WorkFinishedEventArgs> WorkFinished;
        event EventHandler<WorkEventArgs> WorkPaused;
        event EventHandler<WorkEventArgs> WorkResumed;

        #endregion

        #region Methods

        /// <summary>
        /// Started the SimpleWork.
        /// </summary>
        /// <param name="threaded"></param>
        void Start(bool threaded);

        /// <summary>
        /// Abort the SimpleWork.
        /// </summary>
        void Abort();

        #endregion
    }
}
